import React from 'react';
import {unstable_HistoryRouter as HashRouter, Route, Routes} from "react-router-dom";
import AuthComponent from "./AuthComponent";
import Login from "../views/login/Login";
import NewsSandBox from "../views/sandbox/NewsSandBox";
import Home from "../views/sandbox/home/Home";
import UserList from "../views/sandbox/user-manage/UserList";
import RoleList from "../views/sandbox/right-manage/RoleList";
import RightList from "../views/sandbox/right-manage/RightList";
import NoPermission from "../views/sandbox/nopermission/NoPermission";
import history from "../util/history";
import LazyLoad from "./LazyLoad";
import LoginForm from "../components/login/LoginForm";
import RegisterForm from "../components/login/RegisterForm";
import RetrieveForm from "../components/login/RetrieveForm";

const IndexRouter = () => {
  const router = [
    {
      path: "/article/write",
      component: "article/ArticleWrite"
    },
    {
      path: "/article/list",
      component: "article/ArticleList"
    },
    {
      path: "/article/audit",
      component: "article/ArticleAudit"
    },
  ]
  return (
    <HashRouter history={history}>
      <Routes>
        <Route path={"/"} element={<AuthComponent><NewsSandBox/></AuthComponent>}>
          <Route path={"/"} element={<Home/>}/>
          <Route path={"/home"} element={<Home/>}/>
          <Route path={"/user-manage/list"} element={<UserList/>}/>
          <Route path={"/right-manage/role/list"} element={<RoleList/>}/>
          <Route path={"/right-manage/right/list"} element={<RightList/>}/>
          {/*<Route path={"/article/write"} element={<ArticleWrite/>}/>*/}
          {/*<Route path={"/article/write/article/write"} element={import("../views/sandbox/article/ArticleWrite")}/>*/}
          {/*<Route path={"/article/write"} element={LazyLoad("article/ArticleWrite")}/>*/}
          {/*<Route path={"/article/list"} element={<ArticleList/>}/>*/}
          {/*<Route path={"/article/audit"} element={<ArticleAudit/>}/>*/}
          {
            router.map((item, index) => (
              <Route key={index} path={item.path} element={LazyLoad(item.component)}/>
            ))
          }
          <Route path={"*"} element={<NoPermission/>}/>
        </Route>
        <Route path={"/login"} element={<Login/>}>
          <Route path={"/login"} element={<LoginForm/>}/>
          <Route path={"/login/register"} element={<RegisterForm/>}/>
          <Route path={"/login/retrieve"} element={<RetrieveForm/>}/>
        </Route>
      </Routes>
    </HashRouter>
  );
};

export default IndexRouter;